<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="反馈人的姓名" prop="userTrueName">
      <el-input v-model="dataForm.userTrueName" placeholder="反馈人的姓名"></el-input>
    </el-form-item>
    <el-form-item label="反馈人的id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="反馈人的id"></el-input>
    </el-form-item>
    <el-form-item label="反馈内容" prop="feedbackContent">
      <el-input v-model="dataForm.feedbackContent" placeholder="反馈内容"></el-input>
    </el-form-item>
    <el-form-item label="反馈图片一个字符串数组" prop="feedbackImages">
      <el-input v-model="dataForm.feedbackImages" placeholder="反馈图片一个字符串数组"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="反馈处理状态【0 未处理 1 已处理】" prop="status">
      <el-input v-model="dataForm.status" placeholder="反馈处理状态【0 未处理 1 已处理】"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userTrueName: '',
          userId: '',
          feedbackContent: '',
          feedbackImages: '',
          createTime: '',
          status: '',
          updateTime: ''
        },
        dataRule: {
          userTrueName: [
            { required: true, message: '反馈人的姓名不能为空', trigger: 'blur' }
          ],
          userId: [
            { required: true, message: '反馈人的id不能为空', trigger: 'blur' }
          ],
          feedbackContent: [
            { required: true, message: '反馈内容不能为空', trigger: 'blur' }
          ],
          feedbackImages: [
            { required: true, message: '反馈图片一个字符串数组不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '反馈处理状态【0 未处理 1 已处理】不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/order/feedback/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userTrueName = data.feedback.userTrueName
                this.dataForm.userId = data.feedback.userId
                this.dataForm.feedbackContent = data.feedback.feedbackContent
                this.dataForm.feedbackImages = data.feedback.feedbackImages
                this.dataForm.createTime = data.feedback.createTime
                this.dataForm.status = data.feedback.status
                this.dataForm.updateTime = data.feedback.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/order/feedback/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userTrueName': this.dataForm.userTrueName,
                'userId': this.dataForm.userId,
                'feedbackContent': this.dataForm.feedbackContent,
                'feedbackImages': this.dataForm.feedbackImages,
                'createTime': this.dataForm.createTime,
                'status': this.dataForm.status,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
